//
//  sharedPlug.m
//  Runner
//
//  Created by yeqingyu on 2019/7/19.
//  Copyright © 2019 The Chromium Authors. All rights reserved.
//

#import "sharedPlug.h"
#import "QSShareManager.h"
#import "TestViewController.h"
@implementation sharedPlug
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar{
    FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:@"umshared" binaryMessenger:[registrar messenger] ];
    sharedPlug* instance =[sharedPlug new];
    [registrar addMethodCallDelegate:instance channel:channel];
}
-(void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result{
    if ([@"initSdk" isEqualToString:call.method]) {//初始化友盟
        [QSShareManager configUSharePlatforms];
        NSLog(@"配置友盟");
    }else if ([@"sharedData" isEqualToString:call.method]){//分享数据
        NSLog(@"arguments===%@",call.arguments);
        NSDictionary *params = call.arguments;
        NSInteger type = [params[@"type"] integerValue];
        NSString *title = params[@"text"];
        FlutterStandardTypedData *imageData = params[@"image"];
        UIImage *image = [UIImage imageWithData:imageData.data];
        if (type==0) {//分享到微信
           NSLog(@"分享到微信");
//          [QSShareManager shareImageAndTextToPlatformType:UMSocialPlatformType_WechatSession picture:image text:title];
            UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
            NSLog(@"keyWindow===%@",keyWindow);
            NSLog(@"root===%@",keyWindow.rootViewController);
            NSLog(@"nav===%@",keyWindow.rootViewController.navigationController);
            TestViewController *vc = [[TestViewController alloc]init];
            [keyWindow.rootViewController.navigationController pushViewController:vc animated:YES];
        }else if (type==1){//分享到qq
          NSLog(@"QQ");
          [QSShareManager shareImageAndTextToPlatformType:UMSocialPlatformType_QQ picture:image text:title];
        }else{//分享到微博
           NSLog(@"微博");
           [QSShareManager shareImageAndTextToPlatformType:UMSocialPlatformType_Sina picture:image text:title];
        }
        
    }
}
@end
